﻿using UnityEngine;
using System.Collections;
using System;

public class Sculpture : MonoBehaviour
{
    [SerializeField] private Transform itemPrefab;
    [Range(10, 100), SerializeField] private int resolution = 20;
    [SerializeField] private Fun function = Fun.sin;


    private Vector3 _position;
    private Transform[] _points;

    private void Start()
    {
        _points = new Transform[resolution];
        _position.z = 0;
        Vector3 scale = Vector3.one / 8f;
        float cur = resolution / 2;
        for (int i = 0; i < resolution; i++)
        {
            Transform point = Instantiate(itemPrefab);
            _position.x = i / 10f;
            _position.y = Mathf.Sin(_position.x) * 3;
            point.localPosition = _position;
            _points[i] = point;
            point.localScale = scale;
            point.SetParent(transform, false);
        }

    }

    private void Update()
    {
        float t = Time.time;
        for (int i = 0; i < resolution; i++)
        {
            Transform item = _points[i];
            Vector3 position = item.localPosition;
            position.y = GraphFunction.GetFunctions[Convert.ToInt32(function)](position.x, t);
            item.localPosition = position;
        }
    }
}
